package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.deepdesigner.pojo.DtsCouponUser;
import top.deepdesigner.service.DtsCouponUserService;

import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/23 星期五 11:26:22 <br/>
 */
@Service
public class DtsCouponUserServiceImpl extends ServiceImpl<BaseMapper<DtsCouponUser>, DtsCouponUser> implements DtsCouponUserService {
  @Override
  public Long getCouponUserCount() {
    return this.count();
  }

  @Override
  public List<DtsCouponUser> getCouponUserList(Integer page, Integer limit, String sort, String order, String name, Integer couponId, Integer status) {
    QueryWrapper<DtsCouponUser> wrapper = new QueryWrapper<>();
    wrapper.eq(!StringUtils.isEmpty(name), "name", name)
        .eq(couponId != null, "coupon_id", couponId)
        .eq(status != null, "status", status)
        .orderBy(!StringUtils.isEmpty(sort), "asc".equalsIgnoreCase(order), sort);
    return this.page(new Page<>(page, limit), wrapper).getRecords();
  }
}
